<?php
// Get an idea
//
if (!class_exists('fx_control')) {
	require_once ('./application/library/html/fx_control.php');
} 
class fx_sort extends fx_control
{
	// Model Class
	protected $_model;
	// String
	protected $_order = array('name'=>'id', 'direction'=>'desc');
	
	public function __construct() 
	{
		parent::__construct();
	}
	
	// Main Method
	public function sort($order = null, $model = null)
	{
		if (!is_array($order) || count($order) == 0) {
			$order = $this->_order;
		}
		if (!is_null($model)) {
			$this->setModel($model);
		} else {
			if (is_null($this->_model)) {
				return $this;
			}
		}
		$model =& $this->getModel();
		$this->_order = $order;
		$model->resetOrderedList();
		$model->addAttributeOrder($order['name'], $order['direction']);
		return $this;
	}
	
	public function getOrder()
	{
		return $this->_order;
	}
	
	public function setFilter($_order)
	{
		$this->_order = $_order;
		return $this;
	}
	
	public function getModel()
	{
		$model =& $this->_model;
		return $model;
	}
	
	public function setModel($model)
	{
		$this->_model =& $model;
		return $this;
	}
	
	public function getName()
	{
		return $this->_order['name'];
	}
	
	public function getDirection()
	{
		return $this->_order['direction'];
	}
} 